const Controller = require('egg').Controller;
const jwt = require("jsonwebtoken");
const user = [
  {
    username:"gyf",
    password:"gyf",
    author:"TC",
  },{
    username:"1906A",
    password:"1906A",
    author:"USER",
  }
]
const meun = [
  {
    path:"/home",
    title:"首页",
    author:"TC",
  },{
    path:"/home/list",
    title:"列表",
    author:"USER",
  }
]
class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg'  }
  //登录
  async Login(){
    const {ctx} = this;
    const {username,password} = ctx.request.body
    const arr = user.find(item => item.username === username && item.password === password);
   if(arr){
    ctx.body = {
      code:200,
      user:arr,
      token:jwt.sign(arr,"1906A")
    }
   }else{
    ctx.body = {
      code:404,
      msg:"登录失败"
    }
   }
  }
  async Egg_MockData(){
    const {ctx,app} = this;
    const MockData = await app.mysql.select("data");
    ctx.body = {
      code:200,
      message:"前端数据Egg",
      data:MockData
    }
  }
}

module.exports = HomeController;